package com.sftz.modules.admin.log.form;

import java.sql.Timestamp;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.nutz.dao.Cnd;

import com.uxuexi.core.common.util.DateUtil;
import com.uxuexi.core.common.util.Util;
import com.uxuexi.core.web.form.QueryForm;
import com.uxuexi.core.web.form.support.Condition;
import com.uxuexi.core.web.form.support.Condition.MatchType;

@Data
@EqualsAndHashCode(callSuper = true)
public class SLogQueryForm extends QueryForm {

	/**
	 * 操作员名称
	 */
	@Condition(match = MatchType.LIKE)
	private String operatorName;

	/**
	 * 功能名称
	 */
	@Condition(match = MatchType.LIKE)
	private String functionName;

	/**
	 * 操作时间
	 */
	@Condition(match = MatchType.LIKE)
	private Timestamp operatorTime;

	/**
	 * 查询结束时间
	 */
	@Condition(match = MatchType.LIKE)
	private Timestamp queryTimeEnd;

	@Override
	public Cnd createCnd() {
		Cnd cnd = Cnd.NEW();
		cnd.desc("operatorTime");
		if (!Util.isEmpty(operatorName)) {
			cnd.and("operatorName", "like", "%" + operatorName + "%");
		}
		if (!Util.isEmpty(functionName)) {
			cnd.and("functionName", "like", "%" + functionName + "%");
		}
		/**结束时间如果输入日期yyyy-MM-dd，则结束时间需要取当日的最后一秒*/
		Timestamp end = null;
		if (!Util.isEmpty(queryTimeEnd)) {
			end = new Timestamp(queryTimeEnd.getTime() + (DateUtil.MILLIS_OF_DAY - 1));
		}
		//起始时间
		if (!Util.isEmpty(operatorTime) && Util.isEmpty(end)) {
			cnd.and("operatorTime", ">=", operatorTime);
		}
		if (Util.isEmpty(operatorTime) && !Util.isEmpty(end)) {
			cnd.and("operatorTime", "<=", end);
		}
		if (!Util.isEmpty(operatorTime) && !Util.isEmpty(end)) {
			cnd.and("operatorTime", ">=", operatorTime);
			cnd.and("operatorTime", "<=", end);
		}
		return cnd;
	}

}
